package com.wifi.unti;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class LoginUtil {
    public String encroMD5(String pwd)  {
        String passwordmd5 = null;
        while (passwordmd5 == null && pwd != null) {
            try {
                MessageDigest md5 = MessageDigest.getInstance("md5");
                md5.update(pwd.getBytes());
                byte[] digest = md5.digest();
                BigInteger bigInteger = new BigInteger(1, digest);
                passwordmd5 = bigInteger.toString(16);
            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
            }
        }
        return passwordmd5;
    }

    public String getNumeric(String str) {
        String regEx="[^0-9]";
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(str);
        return m.replaceAll("").trim();
    }

//还没想好怎么用
//    public boolean adminLogin(String user,String pwd){
//            Properties propertiesAdmin = new Properties();
//        try {
//            propertiesAdmin.load(LoginUtil.class.getClassLoader().getResourceAsStream("./admin.properties"));
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        if (propertiesAdmin.containsKey("password") && propertiesAdmin.containsKey("username")) {
//        if (propertiesAdmin.getProperty("password").equals(pwd) && propertiesAdmin.getProperty("username").equals(user)) {
//            return true;
//        }
//    }
//return false;
//}


 }
